var loginid,loginuser,loginname,loginkey;
var isjump = 0;//控制翻页
var jumpobj;//跳转对象（page_r 充值  page_c 消费）
var alertmsg = "";
layui.config({
	version:'1510164124181'
}).use(['form','laydate', 'laypage', 'layer', 'element'],function(){
	form = layui.form;
	layer = layui.layer;
	$ = layui.jquery;
    laydate = layui.laydate;//日期
    laypage = layui.laypage;//分页
    element = layui.element; //元素操作
	loginid = $.session.get("userid");
	loginuser = $.session.get("admin_realname");
	loginname = $.session.get("username");
	loginkey = $.session.get("user_secretkey");
	edite_commid = $.session.get("edite_commid");//地区id  为0是添加父级地区，否则为添加子级地区或修改子级或父级地区
	isadd = $.session.get("newcommuity");//0 添加地区  1 修改地区
	if(isadd ==0){
		$("#addrobj").html("添加地区");
		alertmsg = "添加此地区";
		if(edite_commid!=0){
			$("#addrobj").html("添加下级地区");
			alertmsg = "添加此下级地区";
		}
	}else{
		$("#addrobj").html("更改地区");
		alertmsg = "更改此地区";
		initdatas();
	}
});
//初始化数据
function initdatas(){
	$.ajax({
		url: "../../../../service",
		cache: false,
		async: false,
		data: {
			proc: "c_admin.community_selbyid",
			para: "['" + loginname + "','" + loginkey + "',"+(edite_commid*1)+"]"
		},
		dataType: "json",
		success: function(data) {
			console.log(JSON.stringify(data))
			if(data[0].TAG=='0'){
				top.layer.alert(""+data[0].MSG+"",function(index){
				   top.location.href="login.html";
				   layer.close(index);
			    });
			}else if(data[0].TAG=='2'){
			   layer.msg(""+data[0].MSG+"");
			}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
			}else{
			   $("#addr").val(data[0].CNAME);
			}

		}
	});
}
//修改或者添加地区
function update(){
	var addr = $("#addr").val();
	console.log("['" + loginname + "','" + loginkey + "',"+isadd+","+(edite_commid*1)+",'"+addr+"']");
    top.layer.confirm('您确定要'+alertmsg+'吗？',{icon: 3,title:'提示信息'},function(index){
		var index = top.layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
		setTimeout(function(){
			$.ajax({
				url: "../../../../service",
				cache: false,
				data: {
					proc: "c_admin.community_ediet",
					para: "['" + loginname + "','" + loginkey + "',"+isadd+","+(edite_commid*1)+",'"+addr+"']"
				},
				dataType: "json",
				success: function(data) {
					console.log("====="+JSON.stringify(data));
					if(data[0].TAG=='0'){
						top.layer.closeAll();
						top.layer.alert(""+data[0].MSG+"",function(index){
						   top.location.href="login.html";
						   layer.close(index);
					    });
					}else if(data[0].msg=='读取接口失败,参数错误'||data.msg=='读取接口失败,参数错误'){
						top.layer.closeAll();
						top.layer.msg("修改失败，请检查您的网络环境!");
						console.log("读取接口失败,参数错误");
					}else if(data[0].TAG == 2){
						top.layer.msg(""+data[0].MSG+"");
					}else{
						top.layer.closeAll();
						top.layer.msg(""+data[0].MSG+"");
						returnlist();
					}
				}
			});
		},1000);
	})
}
//返回
function returnlist(){
	$.session.remove('edite_commid');
	$.session.remove('newcommuity');
	window.location.href="Jointrader_list.html"
}
